import hashlib
import re
from datetime import datetime

from db import book_col

md5 = lambda x: hashlib.md5(x.encode('utf-8')).hexdigest()

def get_site(url):
    return re.findall(r'(https{0,1}://.*?)/', url)[0]

def formate_mm_dd_time(date_str):
    now = datetime.now()
    current_year = now.year
    date_str = f'{current_year}-{date_str}'
    date_time_obj = datetime.strptime(date_str, "%Y-%m-%d %H:%M")
    return date_time_obj

def formate_yyyy_mm_dd(date_str):
    return datetime.strptime(date_str, "%Y-%m-%d %H:%M")

if __name__ == '__main__':
    book_col.update_many({'updated':0},{'$set':{'updated':1}})